package cn.ffcs.base.dao;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * hibernateSupport扩展<br/>
 * <table>
 * <tr>
 * <td>负责人/principal:</td>
 * <td colspan="2">liuzhh</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author liuzhh
 * @version $Id$
 */
public class ExtendHibernateDaoSupport extends HibernateDaoSupport implements
        IExtendHibernateDaoSupport
{

    /**
     * 实现根据实体值删除对应实体对象
     * @param entity
     * @param a
     */
    public final void batchDelete(Object entity, String a)
    {
        String hql = "delete from " + entity.getClass().getName();
        getSession().createQuery(hql).executeUpdate();
    }

    /**
     * 根据参数和参数值直接删除对应条件数据
     * @param entity
     * @param param
     * @param paramValue
     */
    public final void delete(Object entity, String param, String paramValue)
    {
        String hql = "delete from " + entity.getClass().getName() + " where "
                + param + " = '" + paramValue + "'";
        getSession().createQuery(hql).executeUpdate();
    }

    /**
     * 根据实体名称和参数、参数值进行删除操作
     * @param entityName
     * @param param
     * @param paramValue
     */
    public final void delete(String entityName, String param,
            String paramValue)
    {
        String hql = "delete from " + entityName + " where " + param + " = '"
                + paramValue + "'";
        getSession().createQuery(hql).executeUpdate();
    }

    /**
     * 根据传入的参数和参数值的集合删除数据
     * @param entity
     * @param param
     * @param paramValues
     */
    public void delete(Object entity, String param,
            String[] paramValues)
    {
        if (paramValues != null && paramValues.length > 0)
        {
            for (String value : paramValues)
            {
                String hql = "delete from " + entity.getClass().getName()
                        + " where " + param + " = '" + value + "'";
                getSession().createQuery(hql).executeUpdate();
            }
        }
    }
}
